package com.blog.module.news.controller;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.blog.common.controller.BaseAdminController;
import com.blog.common.mybatis.Page;
import com.blog.module.news.pojo.News;
import com.blog.module.news.service.NewsService;

/**
 * @Title: NewsController.java
 * @Description: TODO
 * @author user
 * @date 2016年7月28日 下午2:42:05
 * @version V1.0
 */
@Controller
@RequestMapping("admin/news/**")
public class NewsAdminController extends BaseAdminController {

	@Autowired
	private NewsService newsService;

	/**
	 * @Title: pageNewsList
	 * @Description: 查询新闻類別
	 * @param
	 * @return String
	 * @throws
	 */
	@RequestMapping("list")
	public String pageNewsList(Model model, News news) {
		news.setUserId(getUser().getId() + "");
		Page page = newsService.newsPageList(news);
		model.addAttribute("page",page);
		return "admin/news/list";
	}
	
	@RequestMapping(value="add",method=RequestMethod.GET)
	public String add() {
		return "admin/news/add";
	}
	@RequestMapping(value="add",method=RequestMethod.POST)
	public String add(News news) {
		newsService.insert(news);
		return redirect("/admin/news/list");
	}
	@RequestMapping(value="/{id}/del",method=RequestMethod.POST)
	public String add(@PathVariable  Integer id ) {
		newsService.delete(id);
		return redirect("/admin/news/list");
	}
}
